package persistence.impl;

import domain.Comment;
import persistence.CommentDAO;
import persistence.DBUtil;

import java.sql.Connection;
import java.sql.PreparedStatement;

public class CommentDAOImpl implements CommentDAO{
    private static final String ADD_COMMENT =
            "INSERT INTO `comment` (user_id,commentInfo) VALUES(?,?)";

    public boolean addComment(Comment comment) {
        boolean flag = false;
        try {
            Connection connection = DBUtil.getConnection();
            PreparedStatement preparedStatement = connection.prepareStatement(ADD_COMMENT);
            preparedStatement.setString(1, comment.getUserid());
            preparedStatement.setString(2, comment.getCommentInfo());
            int row = preparedStatement.executeUpdate();
            if (row == 1) {
                flag = true;
            }
            DBUtil.closeStatement(preparedStatement);
            DBUtil.closeConnection(connection);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return flag;
    }
}
